package main

func longestPalindrome2(s string) string {
	length := len(s)
	dim := make([][]bool, length, length)
	for i := 0; i < length; i++ {
		dim[i] = make([]bool, length)
	}
	max := 0
	result := ""
	for i := 0; i < length; i++ {
		for j := 0; j <= i; j++ {
			dim[j][i] = s[j] == s[i] && (i-j <= 2 || dim[j+1][i-1])
			if dim[j][i] {
				if i-j+1 > max {
					max = i - j + 1
					result = s[j : i+1]
				}
			}
		}
	}
	return result
}
